﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Microsoft.Practices.Unity;
using Microsoft.Practices.EnterpriseLibrary;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Skynet.BusinessLogic.BusinessComponents
{
    public class BCReports : IBCReports
    {
        [Dependency]
        public IUnityContainer ContainerService { get; set; }
        


        [Dependency]
        public DataAccess.IDynamicReportRepository DynamicReportRepository { get; set; }


        public string ExecuteReport(ReportParameters parameters)
        {
            string result = string.Empty;
            var def = this.DynamicReportRepository.GetReportDefinition(parameters.ReportGroup, parameters.ReportName);
            var database = this.ContainerService.Resolve<Database>("SkynetLibrary");            
            var param = new List<string>();
            if (parameters.Param != null)
                param.Add(parameters.Param);

            var reader = database.ExecuteReader(def.reportDefinition, param.ToArray());
            if ( reader.Read())
                result = reader.GetString(0);
            return result;
        }
    }
}
